package com.nuanshui.heatedloan.msgcenter.service.smspush;

import com.nuanshui.heatedloan.msgcenter.model.AliSmsNotificationCodeTemp;
import com.nuanshui.heatedloan.msgcenter.model.AliSmsSecurityCodeTemplateEnum;
import com.nuanshui.heatedloan.msgcenter.model.SmsTemplate;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class SmsTemplateService implements InitializingBean {

    private Map<String,SmsTemplate> smsMap=new HashMap<String,SmsTemplate>();

    public SmsTemplate getTemplate(String code)
    {
        return smsMap.get(code);
    }

    @Override
    public void afterPropertiesSet() throws Exception {

        {
            AliSmsSecurityCodeTemplateEnum[] templates=AliSmsSecurityCodeTemplateEnum.values();

            for (AliSmsSecurityCodeTemplateEnum item: templates) {
                SmsTemplate template=new SmsTemplate();
                template.setCode(item.getTempCode());
                template.setKey(item.getSessionkeyCode());
                template.setType(SmsTemplate.TYPE_VERICODE);
                template.setDesc(item.getSmsInfo());
                smsMap.put(template.getCode(),template);
            }
        }


        {
            AliSmsNotificationCodeTemp[] templates=AliSmsNotificationCodeTemp.values();

            for (AliSmsNotificationCodeTemp item: templates) {
                SmsTemplate template=new SmsTemplate();
                template.setKey(item.getSessionkeyCode());
                template.setCode(item.gettempCode());
                template.setDesc(item.getSmsInfo());
                template.setType(SmsTemplate.TYPE_NOTIFICATION);
                smsMap.put(template.getCode(),template);
            }
        }
    }
}
